/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ExamType;
import java.sql.*;
import java.util.Vector;

/**
 *
 * @author mishra
 */
public class Query {
    static Connection con=null;
    public static int add(ExamTypeBean etb)throws SQLException{
        int i=0;
        try{
            con=DBConnection.Connection.getConnection();
            PreparedStatement pre=con.prepareStatement("insert into EXAM_TYPE values(EXAMTYPEID.nextval,?,sysdate,?)");
            pre.setString(1, etb.getExamTypeName());
            pre.setInt(2, etb.getWeightage());
            i=pre.executeUpdate();
            
        }catch(Exception e){
            System.out.println(e);
        }finally{
            con.close();
        }return i;
    }
public static int edit(ExamTypeBean etb) throws SQLException{
    int i=0;
    try{
        con=DBConnection.Connection.getConnection();
        PreparedStatement pre=con.prepareStatement("update exam_type set exam_type=?, entry_date=sysdate, weightage=? where exam_type_id=?");
        pre.setString(1, etb.getExamTypeName());
        pre.setInt(3, etb.getExamTypeId());
        pre.setInt(2, etb.getWeightage());
        i=pre.executeUpdate();
        
    }catch(Exception e){
        System.out.println(e);
    }finally{
        con.close();
    }return i;
}    
public static Vector viewAll()throws SQLException{
    Vector<Object> list=new Vector<Object>();
    try{
        con=DBConnection.Connection.getConnection();
        PreparedStatement pre=con.prepareStatement("select * from exam_type order by exam_type_id");
        ResultSet rs=pre.executeQuery();
        while(rs.next()){
            ExamTypeBean etb=new ExamTypeBean();
            etb.setExamTypeId(rs.getInt(1));
            etb.setExamTypeName(rs.getString(2));
            etb.setEntryDate(rs.getDate(3));
            etb.setWeightage(rs.getInt(4));
            list.add(etb);
        }
    }catch(Exception e){
        System.out.println(e);
    }finally
    {
        con.close();
    }
    return list;
}
public static ExamTypeBean viewSpecific(String cname, int val)throws SQLException{
    ExamTypeBean etb=new ExamTypeBean();
   try{
        con=DBConnection.Connection.getConnection();
        PreparedStatement pre=con.prepareStatement("select * from exam_type");
        ResultSet rs=pre.executeQuery();
        while(rs.next()){
            
            etb.setExamTypeId(rs.getInt(1));
            etb.setExamTypeName(rs.getString(2));
            etb.setEntryDate(rs.getDate(3));
            etb.setWeightage(rs.getInt(4));
        }
    }catch(Exception e){
        System.out.println(e);
    }finally
    {
        con.close();
    }
    return etb; 
}
public static int delete(int id)throws SQLException{
    int i=0;
    try{
        con=DBConnection.Connection.getConnection();
        PreparedStatement pre=con.prepareStatement("delete from EXAM_TYPE where EXAM_TYPE_ID=?");
        pre.setInt(1, id);
        
        i=pre.executeUpdate();
    }
    catch(Exception e){
        System.out.println(e);
    }finally
    {
        con.close();
    }
    return i; 
}
}
